package wj.tree;

import java.util.ArrayList;

import wj.WJValue;

public class IfStatementNode implements WJNode {

	private ArrayList<IfBlockNode> ifBlocks;
	
	public IfStatementNode(){
		ifBlocks = new ArrayList<IfBlockNode>();
	}
	
	public void addIfBlock(IfBlockNode ifBlock){
		if(ifBlock != null)
			ifBlocks.add(ifBlock);
	}

	@Override
	public WJValue evaluate() {
		for(IfBlockNode ibn : ifBlocks)
			if(ibn.isExpressionTrue())
				return ibn.evaluate();
			
		return WJValue.NULL;
	}

}
